package pers.acp.test.application.task;

import io.gitee.zhangbinhub.acp.boot.base.BaseSpringBootScheduledAsyncTask;
import io.gitee.zhangbinhub.acp.boot.log.LogAdapter;
import io.gitee.zhangbinhub.acp.boot.websocket.servlet.AcpWebSocketServerServlet;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("task2")
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class Task2 extends BaseSpringBootScheduledAsyncTask {

    private final LogAdapter log;

    @Autowired
    public Task2(LogAdapter log) {
        this.log = log;
    }

    @Override
    public boolean beforeExecuteFun() {
        return true;
    }

    @Override
    public Object executeFun() {
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>我是定时任务2》》》》》》》》》》");
        String message = "这是websocket服务端消息";
        log.info("【websocket】广播 >>>>> " + message);
        AcpWebSocketServerServlet.sendMessageToClient(message + "----> 广播");
        log.info("【websocket】单播【1】 >>>>> " + message);
        AcpWebSocketServerServlet.sendMessageToClient(message + "----> 单播", "1");
        return true;
    }

    @Override
    public void afterExecuteFun(@NotNull Object result) {

    }
}
